package com.serookie.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.serookie.entity.Goods;
import com.serookie.entity.GoodsCategory;
import com.serookie.entity.Images;
import com.serookie.mapper.GoodsCategoryMapper;
import com.serookie.mapper.GoodsMapper;
import com.serookie.mapper.ImagesMapper;
import com.serookie.service.GoodsCategoryService;
import com.serookie.service.ImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author kevintam
 * @version 1.0
 * @date 2021/5/5 22:11
 */
@Service
public class ImagesServiceImpl extends ServiceImpl<ImagesMapper, Images> implements ImageService{

    @Autowired
    private ImagesMapper mapper;
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public List<Images> findAll() {
        List<Images> all = mapper.findAll();
        all.forEach(element->{
            Integer goodsId = element.getGoodsId();
            Goods goods = goodsMapper.selectById(goodsId);
            element.setGoodsName(goods.getGoodsName());
        });
        return all;
    }

    @Override
    public Boolean saveImage(Images images) {
        return  mapper.insert(images)>0;
    }

    @Override
    public Images ImagesById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public Boolean deleteImages(Integer id) {
        return mapper.deleteById(id)>0;
    }

    @Override
    public Boolean updateImages(Images images) {
        return mapper.updateById(images)>0;
    }

}
